﻿Public Class frm_RelacaoFinanceiro
    Public inicial As DateTime
    Public final As DateTime

    Public CONTROLE As String

    'COLOCAR NO PRINCIPAL
    'CAP    CAR CP CR EX
    'Dim frm As New GERA_RELATORIOS
    'Dim rpt As New rptReservas
    '        Try
    '            frm.CONTROLE = "CAP"
    '            frm.ShowDialog()
    '        Catch ex As Exception
    '            MessageBox.Show("Erro", "Relatório de Recursos", MessageBoxButtons.OK)
    '        End Try
    '        frm.Dispose()
    '        rpt = Nothing

    Private Sub frm_RelacaoFinanceiro_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        'Dim aux As CrystalDecisions.CrystalReports.Engine.ReportClass
        'aux = Me.CrystalReportViewer1.ReportSource
        'aux.Close()
    End Sub

    Private Sub bPesquisar_Click(sender As System.Object, e As System.EventArgs) Handles bPesquisar.Click
        If (dtinicio.Value.Date <= dtfinal.Value.Date) Then

            inicial = dtinicio.Value
            final = dtfinal.Value

            Select Case CONTROLE
                Case "CAP"
                    Dim rpt As New rel_ContasApagar
                    Try
                        rpt.ParameterFields.Item(0).CurrentValues.AddValue(inicial)
                        rpt.ParameterFields.Item(1).CurrentValues.AddValue(final)
                        CrystalReportViewer1.ReportSource = rpt
                    Catch ex As Exception
                        MessageBox.Show("Erro", "Relatório de Recursos", MessageBoxButtons.OK)
                    End Try
                    rpt = Nothing
                Case "CAR"
                    Dim rpt As New rel_contasAreceber
                    Try
                        rpt.ParameterFields.Item(0).CurrentValues.AddValue(inicial)
                        rpt.ParameterFields.Item(1).CurrentValues.AddValue(final)
                        CrystalReportViewer1.ReportSource = rpt
                    Catch ex As Exception
                        MessageBox.Show("Erro", "Relatório de Recursos", MessageBoxButtons.OK)
                    End Try
                    rpt = Nothing
                Case "CP"
                    Dim rpt As New rel_contasPagas
                    Try
                        rpt.ParameterFields.Item(0).CurrentValues.AddValue(inicial)
                        rpt.ParameterFields.Item(1).CurrentValues.AddValue(final)
                        CrystalReportViewer1.ReportSource = rpt
                    Catch ex As Exception
                        MessageBox.Show("Erro", "Relatório de Recursos", MessageBoxButtons.OK)
                    End Try
                    rpt = Nothing
                Case "CR"
                    Dim rpt As New rel_contasRecebidas
                    Try
                        rpt.ParameterFields.Item(0).CurrentValues.AddValue(inicial)
                        rpt.ParameterFields.Item(1).CurrentValues.AddValue(final)
                        CrystalReportViewer1.ReportSource = rpt
                    Catch ex As Exception
                        MessageBox.Show("Erro", "Relatório de Recursos", MessageBoxButtons.OK)
                    End Try
                    rpt = Nothing
                Case "EX"
                    Dim rpt As New rel_extratoFinanceiro
                    Try
                        rpt.ParameterFields.Item(0).CurrentValues.AddValue(inicial)
                        rpt.ParameterFields.Item(1).CurrentValues.AddValue(final)
                        CrystalReportViewer1.ReportSource = rpt
                    Catch ex As Exception
                        MessageBox.Show("Erro", "Relatório de Recursos", MessageBoxButtons.OK)
                    End Try
                    rpt = Nothing
            End Select
        Else
            MessageBox.Show("DATA INICIAL NAO PODE SER MAIOR QUE FINAL")
        End If
    End Sub

    Private Sub bAjuda_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bAjuda.Click
        Dim Ajuda As String
        Ajuda = Application.StartupPath
        Ajuda = Ajuda.Replace("\bin\Debug", "\Arquivo de Ajuda\relatorios.pdf")
        Dim Ie As Object
        Ie = CreateObject("InternetExplorer.Application")
        Ie.Visible = True
        Ie.Navigate(Ajuda)
    End Sub
End Class